package leetcode.剑指offer.后40;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/1 11:29
 * @description：https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/
 */
public class 剑指_47_礼物的最大价值 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public int maxValue(int[][] grid) {
            for (int i = 0; i < grid.length; i++) {
                for (int j = 0; j < grid[0].length; j++) {
                    if (i == 0 || j == 0) continue;
                    if (i == 0) {
                        grid[i][j] += grid[i][j - 1];
                    } else if (j == 0) {
                        grid[i][j] += grid[i - 1][j];
                    } else
                    grid[i][j] += Math.max(grid[i - 1][j], grid[i][j - 1]);
                }
            }
            return grid[grid.length - 1][grid[0].length - 1];
        }
    }

}
